Analytics: Track Annotation workflow and edit-mode actions with PostHog events#1760
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAnnotation workflows now emit PostHog events for creation, deletion, labeling, editing, focus, tool selection, and drawing. Annotation deletion APIs and undo flows pass annotation types explicitly. ChangesAnnotation analytics and deletion
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant AnnotationUI
participant AnnotationHook
participant PostHog
AnnotationUI->>AnnotationHook: create, update, focus, select, or delete annotation
AnnotationHook->>PostHog: trackEvent(annotation interaction)
PostHog-->>AnnotationHook: tracking completes
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❌ Fast Track: checks did not pass
To run the guardrails locally, from Reflects |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lightly_studio_view/src/lib/components/Header/Header.svelte`:
- Around line 60-68: Move the edit_undo trackEvent call in the keyboard-shortcut
branch after executeReversibleAction(action.id) fulfills, and apply the same
ordering to the other reversible-action path around the referenced lines.
Preserve the existing failure handling so rejected actions do not emit undo
analytics.
In
`@lightly_studio_view/src/lib/hooks/useCreateAnnotation/useCreateAnnotation.test.ts`:
- Around line 15-18: Hoist the trackEvent spy before the Vitest mock factories
execute by defining it through vi.hoisted in both
lightly_studio_view/src/lib/hooks/useCreateAnnotation/useCreateAnnotation.test.ts:15-18
and
lightly_studio_view/src/lib/hooks/useUpdateAnnotationsMutation/useUpdateAnnotationsMutation.test.ts:10-13;
update each usePostHog mock to reuse the hoisted spy, or alternatively convert
the mocks to vi.doMock.
In `@lightly_studio_view/src/lib/hooks/usePostHog.ts`:
- Around line 65-69: Remove the unconditional console.log from trackEvent in
usePostHog; keep posthog.capture(eventName, properties) unchanged so analytics
events continue without exposing payloads in the browser console.
In
`@lightly_studio_view/src/lib/hooks/useUpdateAnnotationsMutation/useUpdateAnnotationsMutation.ts`:
- Around line 31-43: Keep the success-path annotations_bulk_labeled tracking in
useUpdateAnnotationsMutation, and remove the duplicate pre-mutation tracking
from SelectedAnnotations.svelte; update the handler wiring there accordingly so
the event is emitted only after persistence succeeds. Affected sites:
lightly_studio_view/src/lib/hooks/useUpdateAnnotationsMutation/useUpdateAnnotationsMutation.ts
lines 31-43 require no direct change;
lightly_studio_view/src/lib/components/AnnotationsGrid/SelectedAnnotations/SelectedAnnotations.svelte
lines 23-29 must remove the pre-mutation call or rename it to a distinct intent
event, and line 51 must be updated to match the handler change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 91089e24-7720-485c-83be-c4fd6bce7f1b
📒 Files selected for processing (15)
lightly_studio_view/src/lib/components/AnnotationDetails/AnnotationDetailsPanel/AnnotationDetailsPanel.sveltelightly_studio_view/src/lib/components/AnnotationsGrid/SelectedAnnotations/SelectedAnnotations.sveltelightly_studio_view/src/lib/components/Header/Header.sveltelightly_studio_view/src/lib/components/SampleDetails/BrushToolPopUp/BrushToolPopUp.sveltelightly_studio_view/src/lib/components/SampleDetails/SampleDetailsAnnotationSegment/SampleDetailsAnnotationSegment.sveltelightly_studio_view/src/lib/components/SampleDetails/SampleDetailsToolbar/SampleDetailsToolbar.sveltelightly_studio_view/src/lib/components/SampleDetails/SampleObjectDetectionRect/SampleObjectDetectionRect.sveltelightly_studio_view/src/lib/components/SampleDetails/SampleSegmentationMaskRect/SampleSegmentationMaskRect.sveltelightly_studio_view/src/lib/hooks/useCreateAnnotation/useCreateAnnotation.test.tslightly_studio_view/src/lib/hooks/useCreateAnnotation/useCreateAnnotation.tslightly_studio_view/src/lib/hooks/useDeleteAnnotation/useDeleteAnnotation.test.tslightly_studio_view/src/lib/hooks/useDeleteAnnotation/useDeleteAnnotation.tslightly_studio_view/src/lib/hooks/usePostHog.tslightly_studio_view/src/lib/hooks/useUpdateAnnotationsMutation/useUpdateAnnotationsMutation.test.tslightly_studio_view/src/lib/hooks/useUpdateAnnotationsMutation/useUpdateAnnotationsMutation.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e059a3118
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@lightly_studio_view/src/lib/hooks/useAnnotationSelection/useAnnotationSelection.ts`:
- Around line 51-58: Use the shared annotation_focused capture in
useAnnotationSelection for both focus sources, and remove the duplicate
analytics path from SampleDetailsAnnotationSegment: delete the unused usePostHog
import, remove trackEvent destructuring, and remove the local capture block.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f2a73297-94a6-4af8-997a-d073ca92fe85
📒 Files selected for processing (3)
lightly_studio_view/src/lib/components/SampleDetails/SampleDetailsAnnotationSegment/SampleDetailsAnnotationSegment.sveltelightly_studio_view/src/lib/components/SampleDetails/SampleDetailsPanel.sveltelightly_studio_view/src/lib/hooks/useAnnotationSelection/useAnnotationSelection.ts
|
/review |
…ation' of https://github.com/lightly-ai/lightly-studio into leonardo-lig-10227-analytics-track-workflows-data-annotation
What has changed and why?
Instruments nine PostHog events that cover the Annotation workflow and edit-mode interactions.
annotation_tool_selected- fires when the user activates the bounding-box or brush tool; capturescollection_id,tool, andtriggered_by("click"or"keyboard_shortcut")annotation_draw_started- fires on the first canvas mousedown after a drawing tool is selected; capturescollection_id,tool, andparent_sample_typeannotation_created- fires in theonSuccesscallback of the create mutation; capturescollection_id,annotation_type,parent_sample_type, andlabel_nameannotation_label_updated- fires in theonSuccesscallback of the update mutation when exactly one annotation label is changed; capturescollection_idandlabel_nameannotations_bulk_labeled- fires when a label is applied to multiple annotations at once; captured in two places:useUpdateAnnotationsMutation(when the batch contains more than one label update) andSelectedAnnotations(on the bulk-apply action from the annotation grid panel); capturescollection_idandannotation_countannotation_deleted- fires in theonSuccesscallback of the delete mutation; capturescollection_idandannotation_typeedit_mode_started- fires when the user enters edit mode via the "Edit annotations" button or the keyboard toggle key; capturescollection_idandtriggered_byedit_mode_finished- fires when the user exits edit mode via the "Finish Editing" button or the keyboard toggle key; capturescollection_idandtriggered_byedit_undo- fires when the user undoes an action via the Undo button orCmd+Z/Ctrl+Z; only fires when a reversible action actually exists; capturescollection_idandtriggered_byannotation_focused- fires when the user focuses an annotation (selects it), either by clicking on it directly in the canvas or by clicking its row in the side panel; not fired on deselect; capturescollection_id,annotation_type,focus_source("canvas"or"side_panel"), andlabel_nameHow has it been tested?
Unit tests
Did you update CHANGELOG.md?
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Improvements
Tests